// 路由懒加载
// import Home from '@/views/Home'
const Home =()=>import('@/views/Home')
// import Login from '@/views/Login'
const Login =()=>import('@/views/Login')
import Register from '@/views/Register'
import Search from '@/views/Search'
import Detail from '@/views/Detail'
import addCarSuccess from '@/views/addCartSuccess'
import ShopCart from '@/views/ShopCart'
import Trade from '@/views/Trade'
import Pay from '@/views/Pay'
import Paysuccess from '@/views/PaySuccess'
import Center from '@/views/Center'
import Myorder from '@/views/Center/myOrder'
import GroupOrder from '@/views/Center/GroupOrder'

export default [
  { path: '/', redirect: '/home' },
  {
    path: '/home',
    name: 'home',
    component: Home,
    meta: {
      show_footer: true
    }
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta: {
      show_footer: false
    }
  },
  {
    path: '/register',
    component: Register,
    meta: {
      show_footer: false
    }
  },
  {
    path: '/search/:keyword?',
    props: (route) => {
      return { keyword: route.query.keyword }
    },
    name: 'search',
    component: Search,
    meta: {
      show_footer: true
    }
  },
  {
    path: '/detail/:goodsId',
    name: 'detail',
    props: true,
    component: Detail,
    meta: {
      show_footer: true
    }
  },
  {
    path: '/addcarsuccess/:num',
    name: 'addcarsuccess',
    component: addCarSuccess,
    meta: {
      show_footer: true
    }
  },
  {
    path: '/shopcart',
    name: 'shopcart',
    component: ShopCart,
    meta: {
      show_footer: true
    }
  },
  {
    path: '/trade',
    name: 'trade',
    component: Trade,
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 要跳转这组件,必须是从购物车组件来的
      if (from.path == '/shopcart' || from.path == '/trade'||from.path=='/login') next()
      else alert('请从购物车结算跳转')
    }
  },
  {
    path: '/pay',
    name: 'pay',
    component: Pay,
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == '/pay' || from.path == '/trade') next()
      else alert('请从订单页跳转')
    }
  },
  {
    path: '/paysuccess',
    name: 'paysuccess',
    component: Paysuccess,
  },
  {
    path: '/center',
    redirect: '/center/myorder',
    name: 'center',
    component: Center,
    // 子路由
    children: [
      {
        path: 'myorder',
        component: Myorder
      },
      {
        path: 'grouporder',
        component: GroupOrder
      }
    ]
  }
]
